<?php namespace app\service\controller;

use alisms\SendSms;
use alisms\api_demo;
use ronglian\REST;


use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
/**
 * 短信服务层
 */
class Sms {
	
	/**
	 * 发送短信
	 * @param	string	$smsTempCode	短信模板编号
	 * @param	string	$phone			手机号(多个手机号用逗号分割)
	 * @param	array	$params			发送数据
	 */
	public function sendSms($smsTempCode = '', $phone = '', $params = [], $sign = '元福杭州数字科技'){
		switch ($smsTempCode) {
//			验证码
			case 'SMS_322130805':
				if( !isset($params['code']) || empty($params['code']) ){
					$outArr['code'] = '40004';
					return $outArr;
				}
				$params['code'] = $params['code'];
				break;
			default: $outArr['code'] = '40004'; break;
		}
		if( in_array($smsTempCode, ['SMS_322130805']) ){
			$outArr = $this -> sendAliSms($smsTempCode, $phone, $params, $sign);
		}
		return $outArr;
	}
	
	/**
	 * 阿里短信
	 * @param	string	$tempCode	短信模板编号
	 * @param	string	$phone		发送手机号
	 * @param	string	$datas		数据
	 * @param	string	$sign		短信签名
	 */
	private function sendAliSms($tempCode = '', $phone = '', $datas = '', $sign = '元福杭州数字科技'){
		$sign = empty($sign) ? '元福杭州数字科技' : $sign;
		$data['sign'] = $sign;
		$data['code'] = $tempCode;
		$data['phone'] = $phone;
		$data['param'] = $datas;
		
		$alysmsObj = new \alysms\sms\SendSms;
		$result = $alysmsObj::sendSms($tempCode, $phone, $datas, $sign);
		$result = (array)$result;
		
		if (!$result || $result['Code'] != 'OK') $outArr['code'] = '50004';
        if ($result['Code'] == 'OK') $outArr['code'] = '1';
		$outArr['info'] = $result;
		
		return $outArr;
	}
}

?>